package ifosup.marie.fichier;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class ClassMainFichier 
{

	public static void main(String[] args) 
	{
		File rep = new File("repertoireMarie");
		rep.mkdir();
		System.out.println(rep.getAbsolutePath());
		File fileText = new File(rep, "fichier.txt");
		try 
		{
			OutputStream fout = new FileOutputStream(fileText);
			String str = "Hello Word !";
			fout.write(str.getBytes());
			fout.close();
		} 
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
		
		try 
		{
			InputStream fin = new FileInputStream(fileText);
			StringBuffer sb = new StringBuffer();
			int c = 0;
			while ((c = fin.read()) >= 0)
			{
				sb.append((char) c);
			}
			System.out.println(sb);
			fin.close();
		} 
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
		
		FileReader fr;
		try 
		{
			fr = new FileReader(fileText);
			BufferedReader br = new BufferedReader(fr);
			System.out.println(br.readLine());
			fr.close();
		} 
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}		
		
	}

}
